from pathlib import Path
from loguru import logger
from config.log_config import LOG_FOLDER

# 生成存储info信息的对象
file = 'info.log'
info = Path(LOG_FOLDER) / file
# 确保目录存在，如果不存在则创建
info.parent.mkdir(parents=True, exist_ok=True)
if not info.exists():
    info.touch()  # 创建日志文件

# 生成存储error信息的对象
file = 'error.log'
error = Path(LOG_FOLDER) / file
# 确保目录存在，如果不存在则创建
error.parent.mkdir(parents=True, exist_ok=True)
if not error.exists():
    error.touch()  # 创建日志文件


logger.add(info, format="{time} | {level} | {name}:{line} | {message}", level="INFO",filter=lambda record: record["level"].name == "INFO",rotation="1 month", retention="1 year",
compression="zip")


logger.add(error, format="{time} | {level} | {name}:{line} | {message}", level="ERROR",filter=lambda record: record["level"].name == "ERROR",rotation="1 month", retention="1 year",
compression="zip")






